package eu.sudparis.it.opp.graph;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import eu.sudparis.it.opp.Node;
import eu.sudparis.it.opp.observfram.ObserverNode;
import eu.sudparis.it.opp.observfram.Serie;

public class EgoNetwork {
	public ObserverNode bind;
	public HashMap<Integer, List<Serie>> series = new HashMap<Integer, List<Serie>>();

	public List<Node> getNodeSet() {
		List<Node> nds = new ArrayList<Node>();
		for (int i : series.keySet()) {
			Node nd = bind.series.graph.graph.get(i);
			nds.add(nd);
		}
		return nds;
	}

	public void observeEncounter(ObserverNode n1) {
		int idb = n1.id;
		Serie se = new Serie();
		se.start=bind.series.currentTime;
		se.end=-1;
		this.updateEgo(idb, se);
	}

	public void observeLeave(ObserverNode n1) {
		List<Serie> ser = this.series.get(n1.id);
		if (ser==null||ser.size() == 0)
			return;
		Serie tail = ser.get(ser.size() - 1);
		tail.end = this.bind.series.currentTime;
	}

	public void updateEgo(int id2, Serie s) {
		if (!this.series.containsKey(id2)) {
			List<Serie> nser = new ArrayList<Serie>();
			nser.add(s);
			this.series.put(id2, nser);
		} else {
			this.series.get(id2).add(s);
		}
	}

	
	
	public long lastObserved(int id){
		if(!this.series.containsKey(id))
			return Long.MAX_VALUE;
		List<Serie> ser=this.series.get(id);
		return ser.get(ser.size()-1).end;
	}
	
	public EgoNetwork clone() {
		return null;
	}
}
